package com.zqxx.examine.portal.security.handler;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class ExtrAuthenticationSuccessHandler
  extends AbstractAuthenticationTargetUrlRequestHandler
  implements AuthenticationSuccessHandler
{
  public ExtrAuthenticationSuccessHandler() {}
  
  public ExtrAuthenticationSuccessHandler(String defaultTargetUrl)
  {
    setDefaultTargetUrl(defaultTargetUrl);
  }
  
  public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
    throws IOException, ServletException
  {
    handle(request, response, authentication);
    

    clearAuthenticationAttributes(request);
  }
  
  protected final void clearAuthenticationAttributes(HttpServletRequest request)
  {
    HttpSession session = request.getSession(false);
    if (session == null) {
      return;
    }
    session.removeAttribute("SPRING_SECURITY_LAST_EXCEPTION");
  }
}
